package com.whsm.admin.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Slf4j
@Controller
public class FileUpload {
    @PostMapping("/upload")
    public String upload(@RequestParam("email") String email,
                         @RequestParam("username") String username,
                         @RequestPart("headerImg") MultipartFile headerImg,
                         @RequestPart("photos") MultipartFile[] photos) throws IOException {
        log.info(email,username,headerImg.getSize(),photos.length);
        headerImg.transferTo(new File("D:\\upload\\"+headerImg.getOriginalFilename()));
        for (MultipartFile photo : photos) {
            photo.transferTo(new File("D:\\upload\\"+photo.getOriginalFilename()));
        }
        return "main";
    }
}
